﻿using HuiLian.Cloud.ViewModel;
using HuiLian.Cloud.View;
using HuiLian.Cloud.ViewModel.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;

namespace HuiLian.Cloud.ViewModel
{
    public class PaycodeWindowViewModel : ViewModelBase
    {
        /// <summary>
        /// 定时器
        /// </summary>
        private readonly DispatcherTimer timer = new DispatcherTimer();

        public PaycodeWindowViewModel()
        {
            // 设置的间隔为一分钟
            timer.Interval = new TimeSpan(0, 0, 1);
            timer.Tick += TimerTick;
            timer.IsEnabled = true;
            timer.Start();
        }

        private int count = 60;

        public int Count 
        { 
            get { return count; } 
            set 
            { 
                count = value;
                OnPropertyChanged(nameof(Count));
            } 
        }

        private void TimerTick(object sender, EventArgs e)
        {
            if (--Count == 0)
            {
                timer.Stop();
            }
        }
    }
}
